

public class NaiveMoveWithDeadlocks implements MoveRule 
{
	
	boolean[][] deadlocks;
	
	public NaiveMoveWithDeadlocks( boolean[][] deadlocks )
	{
		this.deadlocks = deadlocks;
	}

	@Override
	public boolean isLegalMove(Board board, Move move, Move.Direction direction) 
	{
        
        switch ( board.getCellType(move) ) 
        {
	        case Wall: 				return false;
	        
	        case Player: throw new RuntimeException("Bug i olles regel:3");
	        case PlayerOnGoalSquare: throw new RuntimeException("Bug i olles regel:4");
//	        case Player: break;
//	        case PlayerOnGoalSquare: break;
	        case GoalSquare: break;
	        case EmptyFloor: break;
	        
	        case Box: 
	        case BoxOnGoal:
	        
		        Move boxMove = move.doNewMove( direction );
		        if ( deadlocks[ boxMove.getX() ][ boxMove.getY() ] )
		        {
//		        	System.out.println("deadlock hittad!");
		        	return false;
		        }
		        
		        switch ( board.getCellType(boxMove) ) 
		        {
			        case Wall: 				return false;
			        
			        case Player: throw new RuntimeException("Bug i olles regel:1");
			        case PlayerOnGoalSquare: throw new RuntimeException("Bug i olles regel:2");
			        case GoalSquare: break;
			        case EmptyFloor: break;
			        
			        case Box: 				return false;
			        case BoxOnGoal: 		return false;
	
			        	
			        default: throw new IllegalArgumentException();
		        }
		    break;
	       
	        	
	        default: throw new IllegalArgumentException();
        }
        
        return true;
	}

}
